<template>
	<view>
		<view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="cu-bar" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor, fixed ? 'fixed' : '']">
				<view class="action" @tap="BackPage" v-if="isBack">
					<text class="cuIcon-back"></text>
					<block v-if="backText">{{backText}}</block>
				</view>
				<view style="width: 90rpx;" @tap="BackPage" v-else>
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<view class="action" >
					<slot name="right"></slot>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var StatusBar= this.StatusBar;
				var CustomBar= this.CustomBar;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		props: {
			backText: {
				type: String,
				default() {
					return ''
				}
			},
			// 返回几页
			delta: {
				type: Number,
				default() {
					return 1
				}
			},
			fixed: {
				type: Boolean,
				default: true
			},
			bgColor: {
				type: String,
				default: 'bg-primary'
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		methods: {
			BackPage() {
				const that = this
				if (this.$attrs.backEvt) {
					this.$attrs.backEvt()
					return
				}
				uni.navigateBack({
					delta: that.delta
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bg-primary {
		color: #333;
		background-color: #fff;
	}
	
	.cu-bar {
		display: flex;
		justify-content: space-between;
	}
</style>
